package com.my.spvideo.util.user;

import javax.servlet.http.HttpSession;

public class User {
	//用户状态
	private final HttpSession session;
	private volatile UserProperty property;
	
	public User(HttpSession session,UserProperty property){
		this.session = session;
		this.property = property;
	}

	public void init() {
		session.setAttribute(SessionKeys.USER, this);
	}
	
	/**
	 * 相同的用户发起的请求
	 * @param user
	 * @return
	 */
	public boolean isSameUser(User user){
		return session.getId().equals(user.session.getId());
	}
	
	public void setSessionValue(String key,Object value){
		session.setAttribute(key, value);
	}
	
	public Object getSessionValue(String key){
		return session.getAttribute(key);
	}
	
	public void removeSessionValue(String key){
		session.removeAttribute(key);
	}
	
	public UserProperty getProperty(){
		return property;
	}
	
}
